import { useNavigate } from 'react-router';
import { Index } from '@/components/index.jsx';
import React, { useState } from 'react';
import { useEffect } from 'react';
import { getDepartmentList } from '@/api/basicdata/department';


const columns = [
  {
    title: '编码',
    dataIndex: 'code'
  },
  {
    title: '名称',
    dataIndex: 'name',
  },
  {
    title: '备注',
    dataIndex: 'memo',
  },
  {
    title: '可用状态',
    dataIndex: 'status',
  },
];

const departmentList = () => {
  const searchItems = [
    {
      label: '名称',
      name: 'name',
      type: 'input'
    },
    {
      label: '状态',
      name: 'status',
      type: 'select',
      options: [
        { label: '启用', value: 1 },
        { label: '禁用', value: 0 }
      ]
    }
  ];

  const navigate = useNavigate();
  const data = useState([]);
  useEffect(() => {
    // 获取部门列表
    getDepartmentList();
  }, []);

  /**
   * 新增
   */
  const addFn = () => {
    // 跳转到新增页面
    // navigate('/basicData/department/addDepartment')
    console.log('新增')
  };

  const buttonItems = [
    {
      text: '新增',
      type: 'primary',
      onClick: addFn
    },
    {
      text: '批量删除',
      onClick: () => console.log('批量删除')
    }
  ];

  return (
    <Index
      searchItems={searchItems}
      buttonItems={buttonItems}
      columns={columns}
      dataSource={data}
      loading={false}
      onSearch={(values) => console.log(values)} // todo 需要重写
      pagination={{
        total: 0,
        current: 1,
        pageSize: 10
      }}
    />
  );
};

export default departmentList;